﻿using System;
using System.Collections.Generic;

using System.Text;
using System.Web;

namespace DotNETX.Web.Authority
{
    public class PassLoginRequestValidater : IAuthorityValidater
    {
        public AuthorityValidateResult Validate(System.Web.HttpContext context)
        {
            AuthorityValidateResult r = new AuthorityValidateResult() { Level = 0, Passable = true };
            string ppath = context.Request.PhysicalPath;
            if (ppath != null) ppath = ppath.ToLower();
            if (LoginUrlPhysicalPath != null && ppath == LoginUrlPhysicalPath.ToLower())
            {
                r.Level = int.MaxValue;
            }
            return r;
        }

        protected string temp_loginurl = null;
        protected string temp_loginurl_physicalpath = null;
        public string LoginUrlPhysicalPath
        {
            get
            {
                if (temp_loginurl == Config.LoginUrl)
                {
                    return temp_loginurl_physicalpath;
                }
                else
                {
                    temp_loginurl_physicalpath = HttpContext.Current.Server.MapPath(Config.LoginUrl.Substring(0, Config.LoginUrl.IndexOf('?')));
                    temp_loginurl = Config.LoginUrl;
                    return temp_loginurl_physicalpath;
                }
            }
        }
    }
}
